package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    /**
     * 微信小程序登录
     *
     * @param dto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定老人
     *
     * @param memberElderDto
     * @return
     */
    @ApiOperation("绑定老人")
    @PostMapping("/add")
    public AjaxResult bindElder(@RequestBody MemberElderDto memberElderDto) {
        familyMemberService.add(memberElderDto);
        return AjaxResult.success();
    }

    /**
     * 查询家人列表 用于预约模块
     *
     * @return
     */
    @ApiOperation(value = "查询家人列表")
    @GetMapping("/my")
    public R<List<ElderBindVo>> queryElderBindList() {
        List<ElderBindVo> elderBindVoList = familyMemberService.queryElderBindList();
        return R.ok(elderBindVoList);
    }

    /**
     * 查看已绑定家人列表（分页查询）
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list-by-page")
    @ApiOperation(value = "查看已绑定家人列表（分页查询）")
    public R<List<MemberElderVo>> pageQueryBindedElder(@ApiParam(value = "分页参数-页数", required = true) Integer pageNum,
                                                       @ApiParam(value = "分页参数-每页条数", required = true) Integer pageSize) {
        List<MemberElderVo> memberElderVoList = familyMemberService.pageQueryBindedElder(pageNum, pageSize);
        return R.ok(memberElderVoList);
    }

    /**
     * 查询健康数据
     *
     * @param iotId
     * @return
     */
    @ApiOperation(value = "查询健康数据")
    @GetMapping("/queryServiceProperties/{iotId}")
    public R<List<DeviceDataVo>> queryServiceProperties(@ApiParam(value = "设备id", required = true) @PathVariable String iotId) {
        List<DeviceDataVo> deviceDetailVos = familyMemberService.queryServiceProperties(iotId);
        return R.ok(deviceDetailVos);
    }


    /**
     * 解绑老人
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    @ApiOperation(value = "解绑老人")
    public AjaxResult deleteById(Long id) {
        familyMemberService.deleteById(id);
        return AjaxResult.success();
    }

    /**
     * 按天统计查询指标数据
     * @param iotId
     * @param functionId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByDay(@RequestParam("iotId") String iotId,
                                                               @RequestParam("functionId") String functionId,
                                                               @RequestParam("startTime") Long startTime,
                                                               @RequestParam("endTime") Long endTime) {
        List<DeviceDataGraphVo> deviceDataGraphVos = familyMemberService.queryDeviceDataListByDay(iotId,functionId,startTime,endTime);
        return R.ok(deviceDataGraphVos);
    }

    /**
     * 按周统计查询指标数据
     * @param iotId
     * @param functionId
     * @param startTime
     * @param endTime
     * @return
     */
    @ApiOperation(value = "按周统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(@RequestParam("iotId") String iotId,
                                                                @RequestParam("functionId") String functionId,
                                                                @RequestParam("startTime") Long startTime,
                                                                @RequestParam("endTime") Long endTime){
        List<DeviceDataGraphVo> deviceDataGraphVos = familyMemberService.queryDeviceDataListByWeek(iotId,functionId,startTime,endTime);
        return R.ok(deviceDataGraphVos);
    }

}
